import {
  getCommentListApi,
  CommentActionType,
  SendCommentParamsType,
  sendCommentByIdApi,
} from '@/api/comment';
import { AppDispatch } from '..';
import { ComActionType, CommentType } from '../reducers/comment';

export const getCommentList = (data: CommentActionType) => {
  return async (dispatch: AppDispatch) => {
    const res = await getCommentListApi(data);
    dispatch({ type: 'comment/saveList', payload: res.data });
  };
};

export const clearCommentsAction = (): ComActionType => {
  return { type: 'comment/clearComments' };
};
// 点击回复进行评论
export const setOriginCommentsAction = (
  comment: CommentType
): ComActionType => {
  return { type: 'comment/saveOriginComent', payload: comment };
};
export const clearOriginCommentsAction = (): ComActionType => {
  return { type: 'comment/clearOriginComment' };
};
export const sendCommentByIdAction = (data: SendCommentParamsType) => {
  return async (dispatch: AppDispatch) => {
    const res = await sendCommentByIdApi(data);
    // dispatch({ type: 'comment/saveList', payload: res.data });
    console.log(res);
  };
};
